package com.beiming.libra.domain;

import com.beiming.libra.common.utils.CommonsUtils;
import com.beiming.libra.common.utils.ExcelBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.*;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Table(name = "arbitration_business_disputes")
@Data
@ApiModel(value = "类型要素")
public class ArbitrationBusinessDisputes extends BaseObject {

  /**
   * 案件id
   */
  @Column(name = "case_id")
  @ApiModelProperty(value = "案件id")
  private String caseId;

  /**
   * 纠纷要素类型
   */
  @ApiModelProperty(value = "纠纷要素类型")
  private String type;

  /**
   * 卡号
   */
  @Column(name = "card_no")
  @ApiModelProperty(value = "卡号")
  private String cardNo;

  /**
   * 账号
   */
  @Column(name = "account_no")
  @ApiModelProperty(value = "账号")
  private String accountNo;

  /**
   * 逾期天数
   */
  @Column(name = "overdue_days")
  @ApiModelProperty(value = "逾期天数")
  private Integer overdueDays;

  /**
   * 本金
   */
  @ApiModelProperty(value = "本金")
  private BigDecimal principal;

  /**
   * 开户日
   */
  @Column(name = "open_account_day")
  @ApiModelProperty(value = "开户日")
  private Date openAccountDay;

  /**
   * 利息
   */
  @ApiModelProperty(value = "利息")
  private BigDecimal interests;

  /**
   * 进入催收系统时间
   */
  @Column(name = "collection_system_time")
  @ApiModelProperty(value = "进入催收系统时间")
  private Date collectionSystemTime;

  /**
   * 费用
   */
  @ApiModelProperty(value = "费用")
  private BigDecimal fee;

  /**
   * 提请仲裁日计算日
   */
  @Column(name = "date_of_arbitration")
  @ApiModelProperty(value = "提请仲裁日计算日")
  private Date dateOfArbitration;

  /**
   * 分期类型
   */
  @Column(name = "installment_type")
  @ApiModelProperty(value = "分期类型")
  private String installmentType;

  /**
   * 合同签订日
   */
  @Column(name = "date_of_contract")
  @ApiModelProperty(value = "合同签订日")
  private Date dateOfContract;

  /**
   * 合同名称
   */
  @Column(name = "contract_name")
  @ApiModelProperty(value = "合同名称")
  private String contractName;

  /**
   * 合同编号
   */
  @Column(name = "contract_no")
  @ApiModelProperty(value = "合同编号")
  private String contractNo;

  public ArbitrationBusinessDisputes(ExcelBean excelBean, String caseId) {
    super.setId(CommonsUtils.get32BitUUID());
    this.caseId = caseId;
    this.cardNo = excelBean.getCardNo();
    this.accountNo = excelBean.getAccountNo();
    this.overdueDays = Integer.parseInt(excelBean.getOverdueDays());
    this.principal = new BigDecimal(excelBean.getPrincipal());
    try {
      if (StringUtils.isNotBlank(excelBean.getOpenAccountDay())) {
        this.openAccountDay = new SimpleDateFormat("yyyyMMdd").parse(excelBean.getOpenAccountDay());
      }
    } catch (ParseException e) {
      e.printStackTrace();
    }
    this.interests = new BigDecimal(excelBean.getInterests());
    this.fee = new BigDecimal(excelBean.getFee());
    try {
      if (StringUtils.isNotBlank(excelBean.getDateOfArbitration())) {
        this.dateOfArbitration = new SimpleDateFormat("yyyyMMdd")
            .parse(excelBean.getDateOfArbitration());
      }
    } catch (ParseException e) {
      e.printStackTrace();
    }
    this.installmentType = excelBean.getInstallmentType();
    try {
      if (StringUtils.isNotBlank(excelBean.getDateOfContract())) {
        this.dateOfContract = new SimpleDateFormat("yyyyMMdd").parse(excelBean.getDateOfContract());
      }
    } catch (ParseException e) {
      e.printStackTrace();
    }
    this.contractName = excelBean.getContactName();
    this.contractNo = excelBean.getContactNo();
  }

  public ArbitrationBusinessDisputes() {
  }
}